package com.banmao.action;

import com.banmao.util.IdempotentUtil;
import org.apache.struts2.dispatcher.DefaultActionSupport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class HelloAction extends DefaultActionSupport {

    private static final Logger logger = LoggerFactory.getLogger(HelloAction.class);

    private String name;

    private Integer age;

    @Override
    public String execute() throws Exception {
        boolean idempotent = IdempotentUtil.lock(IdempotentUtil.KeyParam
                .builder()
                .putCtx(name)
                .putCtx(age));
        if (!idempotent) {
            throw new RuntimeException("not idempotent");
        }

        logger.info("-------> enter HelloAction, name:{}, age:{}",
                name, age);
        return "success";
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }
}
